package nowcode;

import java.util.Stack;

public class StackSolution {


    private Stack<Integer> dataStack = new Stack<Integer>();
    private Stack<Integer> minStack = new Stack<Integer>();

    public void push(int node) {
        dataStack.push(node);
        minStack.push(minStack.empty() ? node : Math.min(minStack.peek(), node));
    }

    public void pop() {
        dataStack.pop();
        minStack.pop();
    }

    public int top() {
        return dataStack.peek();
    }

    public int min() {
        return minStack.peek();
    }


    public boolean IsPopOrder(int[] pushA, int[] popA) {

        if (pushA.length == 0) {
            return true;
        }
        Stack<Integer> stack = new Stack<>();

        int popIndex = 0;
        int pushIndex = 0;
        while (popIndex < popA.length) {

            if (stack.isEmpty() || stack.peek() != popA[popIndex]) {
                if (pushIndex == pushA.length) {
                    break;
                }
                stack.push(pushA[pushIndex]);
                pushIndex++;
            }
            if (stack.peek() == popA[popIndex]) {
                stack.pop();
                popIndex++;
            }
        }

        return popIndex == popA.length;

    }
}